<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<s:if test="#request.abook==null">
	<script type="text/javascript">
		location.href = 'showAbook.action';
	</script>
</s:if>

<title>显示通讯录</title>
<script type="text/javascript" src="../js/jquery-1.8.3.min.js"></script>
<script type="text/javascript">
	$(document)
			.ready(
					function() {

						$("#tj").hide();
						$("#gj").click(function() {
							$("#tj").toggle();
						});

						/**
						 *获取性别的json
						 **/

						$.getJSON(
										"byTypeDDL.action",
										{
											"ddl.typeType" : "性别"
										},
										function(result) {
											var str = "<select  id='xb' name='addressBook.DDLByTypeSex.typeId'><option value=''>==请选择性别==</option>";
											for ( var i = 0; i < result.length; i++) {
												str += '<option value="'+result[i].value+'">'
														+ result[i].value
														+ ' </option>';

											}
											$("#sex").append(str);

										});
						/**
						 *获取部门的json
						 **/
						$
								.getJSON(
										"byTypeDDL.action",
										{
											"ddl.typeType" : "部门"
										},
										function(result2) {
											var str = "<select  id='bm' name='addressBook.DDLByTypeDepartments.typeId'><option value=''>==请选择部门==</option>";
											for ( var i = 0; i < result2.length; i++) {
												str += '<option value="'+result2[i].value+'">'
														+ result2[i].value
														+ '</option>';
											}
											str += '</select>';
											$("#departement").append(str);

										});
						/**
						 *获取职务json
						 **/
						$
								.getJSON(
										"byTypeDDL.action",
										{
											"ddl.typeType" : "职务"
										},
										function(result1) {
											var str = "<select id='zw' name='addressBook.DDLByTypeDutiesname.typeId'><option value=''>==请选择职务==</option>";
											for ( var i = 0; i < result1.length; i++) {
												str += '<option value="'+result1[i].value+'">'
														+ result1[i].value
														+ '</option>';
											}
											str += '</select>';
											$("#dutiesName").append(str);

										});

						//全选全不选
						$("input[name=all]").click(function() {

							$("input[name=xz]").attr("checked", this.checked);

						});

						//单个的选择
						var $subBox = $("input[name='xz']");

						$subBox
								.click(function() {
									$("#qx")
											.attr(
													"checked",
													$subBox.length == $("input[name='xz']:checked").length ? true
															: false);
								});

					});

	/**
	 *简单查询
	 */
	function search1() {
		$.getJSON("search1Abook.action", {
			"addressBook.customer.custName" : $("#cusname").val()
		}, function(s1) {
			temp(s1);
		});

	}

	/**
	 *高级查询
	 */
	function search2() {
		$.getJSON("search2Abook.action", {
			"addressBook.customer.custName" : $("#cusname").val(),
			"addressBook.DDLByTypeSex.typeValue" : $("#xb").val(),
			"addressBook.DDLByTypeDepartments.typeValue" : $("#bm").val(),
			"addressBook.DDLByTypeDutiesname.typeValue" : $("#zw").val(),
			"addressBook.abTellphone" : $("#dh").val(),
			"addressBook.abProname" : $("#xm").val(),
			"addressBook.abAddress" : $("#dz").val()
		}, function(s2) {
			temp(s2);
		});
	}

	/**
	 *下拉级联
	 */
	function tooltip() {
		$.getJSON("tooltipAbook.action", {
			"addressBook.customer.custName" : $("#cusname").val()
		}, function(tt) {
			temp(tt);
		});

	}

	/**
	 *用于添加到表格中的方法
	 */
	function temp(t) {
		var str = "";
		for ( var i = 0; i < t.length; i++) {
			str += '<tr><td><input type="checkbox" name="xz" id="xx" value='+t[i].abProid+'></td><td>'
					+ t[i].abProid
					+ '</td><td>'
					+ t[i].customer
					+ '</td><td>'
					+ t[i].ddlSex
					+ '</td><td>'
					+ t[i].ddlDepartement
					+ '</td><td>'
					+ t[i].ddlDutiesname
					+ '</td><td>'
					+ t[i].abTellphone
					+ '</td><td>'
					+ t[i].abZipcode
					+ '</td><td>'
					+ t[i].abEmail
					+ '</td><td>'
					+ t[i].abQq
					+ '</td><td>'
					+ t[i].abProname
					+ '</td><td>'
					+ t[i].abInterest
					+ '</td><td>'
					+ t[i].abBirth
					+ '</td><td>'
					+ t[i].abAddress
					+ '</td><td><a href="getAbook.action?addressBook.abProid='
					+ t[i].abProid
					+ '">修改</a>&nbsp;&nbsp;&nbsp;<a href="delAbook.action?addressBook.abProid='
					+ t[i].abProid + '">删除</a></td></tr>';
		}
		$("#mytr").html("");
		$("#mytr").append(str);

	}

	function excel() {
		var path = 'excelAbook.action';
		var xz = '';
		$('input[name="xz"]:checked').each(function() {
			xz += $(this).val() + ',';
		});
		//alert(xz.length);
		xz = xz.substring(0, xz.length - 1);
		if (xz.length == 0) {
			location.href = path;
		} else {
			location.href = path + '?xz=' + xz;
		}

	}
</script>
<link href="../css/table.css" rel="stylesheet" type="text/css">
</head>
<body>
<div id="search"> <input type="text" border="1" id="cusname"
				onkeyup="tooltip();" /> &nbsp; &nbsp; &nbsp; &nbsp;<input
				type="button" value="  搜  索   " onclick="search1();" /> &nbsp; &nbsp;
				<span id="gj" style="color: blue;">高级搜索
				<input type="button" value="添加"
		onClick="location.href='addAddressBook.jsp'">
				<input type="button" value="导出excel" onClick="excel();">
				</span></div>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
		<tr id="tj">
			<td>
					<table width="100%" align="center" style="text-align: center;">

						<tr>
							<td class="table_rightf">性别：</td>
							<td class="tableleftf" id="sex"></td>
						</tr>

						<tr>
							<td class="table_rightf">客户所属部门：</td>
							<td class="tableleftf" id="departement"></td>
						</tr>

						<tr>
							<td class="table_rightf">客户职务 ：</td>
							<td class="tableleftf" id="dutiesName"></td>
						</tr>

						<tr>
							<td class="table_rightf">电话：</td>
							<td class="tableleftf"><input type="text" id="dh"
								name="addressBook.abTellphone" /></td>
						</tr>


						<tr>
							<td class="table_rightf">联系人姓名：</td>
							<td class="tableleftf"><input id="xm" type="text" name="addressBook.abProname" /></td>
						</tr>

						<tr>
							<td class="table_rightf">地址：</td>
							<td class="tableleftf"><input id="dz" type="text" name="addressBook.abAddress" /></td>
						</tr>
						<tr>
							<td colspan="2" align="right"><input type="button"
								value="查询" onclick="search2();"></td>

						</tr>
					</table>
		</tr>

	</table>
<hr color="purple" />

	<table width="100%" border="0" cellpadding="0" cellspacing="0">
		<thead align="center">
			<tr>
				<td>全选<input type="checkbox" id="qx" name="all"></td>
				<td>编号</td>
				<td>客户名称</td>
				<td>性别</td>
				<td>客户所属部门</td>
				<td>客户职务</td>
				<td>电话</td>
				<td>邮编</td>
				<td>邮箱</td>
				<td>QQ</td>
				<td>联系人姓名</td>
				<td>兴趣爱好</td>
				<td>生日</td>
				<td>地址</td>
				<td>操作</td>

			</tr>
		</thead>
		<tbody id="mytr" align="center">
			<s:iterator value="#request.abook">
				<tr>
					<td><input type="checkbox" name="xz" id="xx"
						value="<s:property value="abProid" />"></td>

					<td><s:property value="abProid" /><input type="hidden"
						value="<s:property value="abProid" />" id="id"></td>
					<td><s:property value="customer.custName" /></td>
					<td><s:property value="DDLByTypeSex.typeValue" /></td>
					<td><s:property value="DDLByTypeDepartments.typeValue" /></td>
					<td><s:property value="DDLByTypeDutiesname.typeValue" /></td>
					<td><s:property value="abTellphone" /></td>
					<td><s:property value="abZipcode" /></td>
					<td><s:property value="abEmail" /></td>
					<td><s:property value="abQq" /></td>
					<td><s:property value="abProname" /></td>
					<td><s:property value="abInterest" /></td>
					<td><s:property value="abBirth" /></td>
					<td><s:property value="abAddress" /></td>
					<td><a
						href="getAbook.action?addressBook.abProid=<s:property value="abProid" />">修改</a>&nbsp;&nbsp;&nbsp;<a
						href="delAbook.action?addressBook.abProid=<s:property value="abProid" />">删除</a></td>

				</tr>

			</s:iterator>


		</tbody>
		<tfoot>
			<tr align="right" style="color: blue;">
				<td colspan="15" style="color: blue;">共<s:property
						value="pagecount" />页&nbsp;&nbsp;&nbsp;<a
					href="showAbook.action?currpage=1">首页</a>&nbsp;&nbsp;&nbsp; <a
					href="showAbook.action?currpage=<s:property value="currpage-1" />">上一页</a>&nbsp;&nbsp;&nbsp;第<s:property
						value="currpage" />页&nbsp;&nbsp;&nbsp;<a
					href="showAbook.action?currpage=<s:property value="currpage+1" />">下一页</a>&nbsp;&nbsp;&nbsp;<a
					href="showAbook.action?currpage=<s:property value="pagecount" />">尾页</a>
				</td>

			</tr>

		</tfoot>

	</table>

	<script type="text/javascript">
		function fy(val) {
			var cuCurTab = 1;
			if (val == 1) {
				CurTab++;
				alert(CurTab);
			} else if (val == -1) {
				CurTab--;
				if (cuCurTab < 1)
					cuCurTab = 1;
				alert(CurTab);
			} else if (val == 0) {
				CurTab = 1;
				nPage = 1;
				alert(CurTab);
			} else {
				alert(0);
			}

		}
	</script>

</body>
</html>